<?php
namespace Admin\Controller;
use Think\Controller;
require "./Application/Admin/Common/Common/function.php";
class ArticleController extends Controller {

	  public function _initialize(){
        if (empty($_SESSION['user'])) {
           $this->error('请登入',U('Admin/Login/login'));
        }
    }

    //文章管理显示页面
    public function index(){
    	  $m = M('article_content');      
        $count = $m->count();
        $p = getpage($count,10);
        $list = $m->field(true)->where($where)->order('id')->limit($p->firstRow, $p->listRows)->select();
        $this->assign('str1', $list); // 赋值数据集
        $this->assign('page', $p->show()); // 赋值分页输出
        $this->display();
    }


    public function edit(){
        $id = I('get.id');
        $str = M('article_content')->where("id=".$id)->find();
        $str1 = M('article_kind')->select();
        $this->assign('str',$str);
        $this->assign('str1',$str1);
        $this->display();

    }


    public function edit_do(){
      $datas = M('article_content');
      $datas->id = I('POST.id');  
      $datas->title = I('POST.title');  
      $datas->author = I('POST.author');  
      $datas->content = I('POST.content');  
      $datas->kid=I('POST.modules'); 
      if($datas->save()) {
        $this->success('修改成功',U('Admin/Article/index'));
      }else{
        $this->error('修改失败');
      }
    }


    public function dele(){    
      $id = I('get.id');  
      $str=M('article_content')->where('id='.$id)->delete();
      if($str){
        $this->success('删除成功',U('Admin/Article/index'));
      }else{
        $this->error('修改失败');
      }
    }


    public function add(){
      $str1 = M('article_kind')->select();
      $this->assign('str',$str1);   
      $this->display();

    }


      public function add_do(){
        $datas=M('article_content');
        $datas->title=I('post.title');
        $datas->author=I('post.author');
        $datas->addtime=strtotime(I('post.date'));
        $datas->content=I('post.content');
        $datas->kid=I('post.modules');
        if($datas->add()){
            $this->success('添加成功',U('Admin/Article/index'));
        }else{
            $this->error('添加失败');
        }
    }

    

}